﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria.GameContent.Generation;
using Terraria.ID;
using Terraria.World.Generation;

namespace Terraria.GameContent.Biomes
{
	// Token: 0x0200044C RID: 1100
	public class CaveHouseBiome : MicroBiome
	{
		// Token: 0x060025CA RID: 9674 RVA: 0x0048A684 File Offset: 0x00488884
		private Rectangle GetRoom(Point origin)
		{
			Point point;
			bool flag = WorldUtils.Find(origin, Searches.Chain(new Searches.Left(25), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point);
			Point point2;
			bool flag2 = WorldUtils.Find(origin, Searches.Chain(new Searches.Right(25), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point2);
			if (!flag)
			{
				point = new Point(origin.X - 25, origin.Y);
			}
			if (!flag2)
			{
				point2 = new Point(origin.X + 25, origin.Y);
			}
			Rectangle rectangle = new Rectangle(origin.X, origin.Y, 0, 0);
			if (origin.X - point.X > point2.X - origin.X)
			{
				rectangle.X = point.X;
				rectangle.Width = Utils.Clamp<int>(point2.X - point.X, 15, 30);
			}
			else
			{
				rectangle.Width = Utils.Clamp<int>(point2.X - point.X, 15, 30);
				rectangle.X = point2.X - rectangle.Width;
			}
			Point point3;
			bool flag3 = WorldUtils.Find(point, Searches.Chain(new Searches.Up(10), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point3);
			Point point4;
			bool flag4 = WorldUtils.Find(point2, Searches.Chain(new Searches.Up(10), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point4);
			if (!flag3)
			{
				point3 = new Point(origin.X, origin.Y - 10);
			}
			if (!flag4)
			{
				point4 = new Point(origin.X, origin.Y - 10);
			}
			rectangle.Height = Utils.Clamp<int>(Math.Max(origin.Y - point3.Y, origin.Y - point4.Y), 8, 12);
			rectangle.Y -= rectangle.Height;
			return rectangle;
		}

		// Token: 0x060025CB RID: 9675 RVA: 0x0048A858 File Offset: 0x00488A58
		private float RoomSolidPrecentage(Rectangle room)
		{
			float num = (float)(room.Width * room.Height);
			Ref<int> @ref = new Ref<int>(0);
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.IsSolid(),
				new Actions.Count(@ref)
			}));
			return (float)@ref.Value / num;
		}

		// Token: 0x060025CC RID: 9676 RVA: 0x0048A8C8 File Offset: 0x00488AC8
		private bool FindVerticalExit(Rectangle wall, bool isUp, out int exitX)
		{
			Point point;
			bool result = WorldUtils.Find(new Point(wall.X + wall.Width - 3, wall.Y + (isUp ? -5 : 0)), Searches.Chain(new Searches.Left(wall.Width - 3), new GenCondition[]
			{
				new Conditions.IsSolid().Not().AreaOr(3, 5)
			}), out point);
			exitX = point.X;
			return result;
		}

		// Token: 0x060025CD RID: 9677 RVA: 0x0048A938 File Offset: 0x00488B38
		private bool FindSideExit(Rectangle wall, bool isLeft, out int exitY)
		{
			Point point;
			bool result = WorldUtils.Find(new Point(wall.X + (isLeft ? -4 : 0), wall.Y + wall.Height - 3), Searches.Chain(new Searches.Up(wall.Height - 3), new GenCondition[]
			{
				new Conditions.IsSolid().Not().AreaOr(4, 3)
			}), out point);
			exitY = point.Y;
			return result;
		}

		// Token: 0x060025CE RID: 9678 RVA: 0x0048A9A8 File Offset: 0x00488BA8
		private int SortBiomeResults(Tuple<CaveHouseBiome.BuildData, int> item1, Tuple<CaveHouseBiome.BuildData, int> item2)
		{
			return item2.Item2.CompareTo(item1.Item2);
		}

		// Token: 0x060025CF RID: 9679 RVA: 0x0048A9CC File Offset: 0x00488BCC
		public override bool Place(Point origin, StructureMap structures)
		{
			Point point;
			bool flag = WorldUtils.Find(origin, Searches.Chain(new Searches.Down(200), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point);
			if (!flag || point == origin)
			{
				return false;
			}
			Rectangle room = this.GetRoom(point);
			Rectangle rectangle = this.GetRoom(new Point(room.Center.X, room.Y + 1));
			Rectangle rectangle2 = this.GetRoom(new Point(room.Center.X, room.Y + room.Height + 10));
			rectangle2.Y = room.Y + room.Height - 1;
			float num = this.RoomSolidPrecentage(rectangle);
			float num2 = this.RoomSolidPrecentage(rectangle2);
			room.Y += 3;
			rectangle.Y += 3;
			rectangle2.Y += 3;
			List<Rectangle> list = new List<Rectangle>();
			if (GenBase._random.NextFloat() > num + 0.2f)
			{
				list.Add(rectangle);
			}
			else
			{
				rectangle = room;
			}
			list.Add(room);
			if (GenBase._random.NextFloat() > num2 + 0.2f)
			{
				list.Add(rectangle2);
			}
			else
			{
				rectangle2 = room;
			}
			foreach (Rectangle rectangle3 in list)
			{
				if (rectangle3.Y + rectangle3.Height > Main.maxTilesY - 220)
				{
					return false;
				}
			}
			Dictionary<ushort, int> dictionary = new Dictionary<ushort, int>();
			foreach (Rectangle rectangle4 in list)
			{
				WorldUtils.Gen(new Point(rectangle4.X - 10, rectangle4.Y - 10), new Shapes.Rectangle(rectangle4.Width + 20, rectangle4.Height + 20), new Actions.TileScanner(new ushort[]
				{
					0,
					59,
					147,
					1,
					161,
					53,
					396,
					397,
					368,
					367,
					60,
					70
				}).Output(dictionary));
			}
			List<Tuple<CaveHouseBiome.BuildData, int>> list2 = new List<Tuple<CaveHouseBiome.BuildData, int>>();
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Default, dictionary[0] + dictionary[1]));
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Jungle, dictionary[59] + dictionary[60] * 10));
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Mushroom, dictionary[59] + dictionary[70] * 10));
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Snow, dictionary[147] + dictionary[161]));
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Desert, dictionary[397] + dictionary[396] + dictionary[53]));
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Granite, dictionary[368]));
			list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Marble, dictionary[367]));
			list2.Sort(new Comparison<Tuple<CaveHouseBiome.BuildData, int>>(this.SortBiomeResults));
			CaveHouseBiome.BuildData item = list2[0].Item1;
			foreach (Rectangle rectangle5 in list)
			{
				if (item != CaveHouseBiome.BuildData.Granite)
				{
					Point point2;
					bool flag2 = WorldUtils.Find(new Point(rectangle5.X - 2, rectangle5.Y - 2), Searches.Chain(new Searches.Rectangle(rectangle5.Width + 4, rectangle5.Height + 4).RequireAll(false), new GenCondition[]
					{
						new Conditions.HasLava()
					}), out point2);
					if (flag2)
					{
						return false;
					}
				}
				if (!structures.CanPlace(rectangle5, CaveHouseBiome._blacklistedTiles, 5))
				{
					return false;
				}
			}
			int num3 = room.X;
			int num4 = room.X + room.Width - 1;
			List<Rectangle> list3 = new List<Rectangle>();
			foreach (Rectangle rectangle6 in list)
			{
				num3 = Math.Min(num3, rectangle6.X);
				num4 = Math.Max(num4, rectangle6.X + rectangle6.Width - 1);
			}
			int num5 = 6;
			while (num5 > 4 && (num4 - num3) % num5 != 0)
			{
				num5--;
			}
			for (int i = num3; i <= num4; i += num5)
			{
				for (int j = 0; j < list.Count; j++)
				{
					Rectangle rectangle7 = list[j];
					if (i >= rectangle7.X && i < rectangle7.X + rectangle7.Width)
					{
						int num6 = rectangle7.Y + rectangle7.Height;
						int num7 = 50;
						for (int k = j + 1; k < list.Count; k++)
						{
							if (i >= list[k].X && i < list[k].X + list[k].Width)
							{
								num7 = Math.Min(num7, list[k].Y - num6);
							}
						}
						if (num7 > 0)
						{
							Point point3;
							bool flag3 = WorldUtils.Find(new Point(i, num6), Searches.Chain(new Searches.Down(num7), new GenCondition[]
							{
								new Conditions.IsSolid()
							}), out point3);
							if (num7 < 50)
							{
								flag3 = true;
								point3 = new Point(i, num6 + num7);
							}
							if (flag3)
							{
								list3.Add(new Rectangle(i, num6, 1, point3.Y - num6));
							}
						}
					}
				}
			}
			List<Point> list4 = new List<Point>();
			foreach (Rectangle rectangle8 in list)
			{
				int y;
				bool flag4 = this.FindSideExit(new Rectangle(rectangle8.X + rectangle8.Width, rectangle8.Y + 1, 1, rectangle8.Height - 2), false, out y);
				if (flag4)
				{
					list4.Add(new Point(rectangle8.X + rectangle8.Width - 1, y));
				}
				flag4 = this.FindSideExit(new Rectangle(rectangle8.X, rectangle8.Y + 1, 1, rectangle8.Height - 2), true, out y);
				if (flag4)
				{
					list4.Add(new Point(rectangle8.X, y));
				}
			}
			List<Tuple<Point, Point>> list5 = new List<Tuple<Point, Point>>();
			for (int l = 1; l < list.Count; l++)
			{
				Rectangle rectangle9 = list[l];
				Rectangle rectangle10 = list[l - 1];
				int num8 = rectangle10.X - rectangle9.X;
				int num9 = rectangle9.X + rectangle9.Width - (rectangle10.X + rectangle10.Width);
				if (num8 > num9)
				{
					list5.Add(new Tuple<Point, Point>(new Point(rectangle9.X + rectangle9.Width - 1, rectangle9.Y + 1), new Point(rectangle9.X + rectangle9.Width - rectangle9.Height + 1, rectangle9.Y + rectangle9.Height - 1)));
				}
				else
				{
					list5.Add(new Tuple<Point, Point>(new Point(rectangle9.X, rectangle9.Y + 1), new Point(rectangle9.X + rectangle9.Height - 1, rectangle9.Y + rectangle9.Height - 1)));
				}
			}
			List<Point> list6 = new List<Point>();
			int x;
			bool flag5 = this.FindVerticalExit(new Rectangle(rectangle.X + 2, rectangle.Y, rectangle.Width - 4, 1), true, out x);
			if (flag5)
			{
				list6.Add(new Point(x, rectangle.Y));
			}
			flag5 = this.FindVerticalExit(new Rectangle(rectangle2.X + 2, rectangle2.Y + rectangle2.Height - 1, rectangle2.Width - 4, 1), false, out x);
			if (flag5)
			{
				list6.Add(new Point(x, rectangle2.Y + rectangle2.Height - 1));
			}
			foreach (Rectangle rectangle11 in list)
			{
				WorldUtils.Gen(new Point(rectangle11.X, rectangle11.Y), new Shapes.Rectangle(rectangle11.Width, rectangle11.Height), Actions.Chain(new GenAction[]
				{
					new Actions.SetTile(item.Tile, false, true),
					new Actions.SetFrames(true)
				}));
				WorldUtils.Gen(new Point(rectangle11.X + 1, rectangle11.Y + 1), new Shapes.Rectangle(rectangle11.Width - 2, rectangle11.Height - 2), Actions.Chain(new GenAction[]
				{
					new Actions.ClearTile(true),
					new Actions.PlaceWall(item.Wall, true)
				}));
				structures.AddStructure(rectangle11, 8);
			}
			foreach (Tuple<Point, Point> tuple in list5)
			{
				Point item2 = tuple.Item1;
				Point item3 = tuple.Item2;
				int num10 = (item3.X > item2.X) ? 1 : -1;
				ShapeData shapeData = new ShapeData();
				for (int m = 0; m < item3.Y - item2.Y; m++)
				{
					shapeData.Add(num10 * (m + 1), m);
				}
				WorldUtils.Gen(item2, new ModShapes.All(shapeData), Actions.Chain(new GenAction[]
				{
					new Actions.PlaceTile(19, item.PlatformStyle),
					new Actions.SetSlope((num10 == 1) ? 1 : 2),
					new Actions.SetFrames(true)
				}));
				WorldUtils.Gen(new Point(item2.X + ((num10 == 1) ? 1 : -4), item2.Y - 1), new Shapes.Rectangle(4, 1), Actions.Chain(new GenAction[]
				{
					new Actions.Clear(),
					new Actions.PlaceWall(item.Wall, true),
					new Actions.PlaceTile(19, item.PlatformStyle),
					new Actions.SetFrames(true)
				}));
			}
			foreach (Point point4 in list4)
			{
				WorldUtils.Gen(point4, new Shapes.Rectangle(1, 3), new Actions.ClearTile(true));
				WorldGen.PlaceTile(point4.X, point4.Y, 10, true, true, -1, item.DoorStyle);
			}
			foreach (Point origin2 in list6)
			{
				WorldUtils.Gen(origin2, new Shapes.Rectangle(3, 1), Actions.Chain(new GenAction[]
				{
					new Actions.ClearMetadata(),
					new Actions.PlaceTile(19, item.PlatformStyle),
					new Actions.SetFrames(true)
				}));
			}
			foreach (Rectangle rectangle12 in list3)
			{
				if (rectangle12.Height > 1 && GenBase._tiles[rectangle12.X, rectangle12.Y - 1].type != 19)
				{
					WorldUtils.Gen(new Point(rectangle12.X, rectangle12.Y), new Shapes.Rectangle(rectangle12.Width, rectangle12.Height), Actions.Chain(new GenAction[]
					{
						new Actions.SetTile(124, false, true),
						new Actions.SetFrames(true)
					}));
					Tile tile = GenBase._tiles[rectangle12.X, rectangle12.Y + rectangle12.Height];
					tile.slope(0);
					tile.halfBrick(false);
				}
			}
			Point[] choices = new Point[]
			{
				new Point(14, item.TableStyle),
				new Point(16, 0),
				new Point(18, item.WorkbenchStyle),
				new Point(86, 0),
				new Point(87, item.PianoStyle),
				new Point(94, 0),
				new Point(101, item.BookcaseStyle)
			};
			foreach (Rectangle rectangle13 in list)
			{
				int num11 = rectangle13.Width / 8;
				int num12 = rectangle13.Width / (num11 + 1);
				int num13 = GenBase._random.Next(2);
				for (int n = 0; n < num11; n++)
				{
					int num14 = (n + 1) * num12 + rectangle13.X;
					int num15 = n + num13 % 2;
					if (num15 != 0)
					{
						if (num15 == 1)
						{
							int num16 = rectangle13.Y + 1;
							WorldGen.PlaceTile(num14, num16, 34, true, false, -1, GenBase._random.Next(6));
							for (int num17 = -1; num17 < 2; num17++)
							{
								for (int num18 = 0; num18 < 3; num18++)
								{
									Tile tile2 = GenBase._tiles[num17 + num14, num18 + num16];
									Tile tile3 = tile2;
									tile3.frameX += 54;
								}
							}
						}
					}
					else
					{
						int num19 = rectangle13.Y + Math.Min(rectangle13.Height / 2, rectangle13.Height - 5);
						Vector2 vector = WorldGen.randHousePicture();
						int type = (int)vector.X;
						int style = (int)vector.Y;
						if (!WorldGen.nearPicture(num14, num19))
						{
							WorldGen.PlaceTile(num14, num19, type, true, false, -1, style);
						}
					}
				}
				for (int num20 = rectangle13.Width / 8 + 3; num20 > 0; num20--)
				{
					int num21 = GenBase._random.Next(rectangle13.Width - 3) + 1 + rectangle13.X;
					int num22 = rectangle13.Y + rectangle13.Height - 2;
					switch (GenBase._random.Next(4))
					{
					case 0:
						WorldGen.PlaceSmallPile(num21, num22, GenBase._random.Next(31, 34), 1, 185);
						break;
					case 1:
						WorldGen.PlaceTile(num21, num22, 186, true, false, -1, GenBase._random.Next(22, 26));
						break;
					case 2:
					{
						int num23 = GenBase._random.Next(2, WorldGen.statueList.Length);
						WorldGen.PlaceTile(num21, num22, (int)WorldGen.statueList[num23].X, true, false, -1, (int)WorldGen.statueList[num23].Y);
						if (WorldGen.StatuesWithTraps.Contains(num23))
						{
							WorldGen.PlaceStatueTrap(num21, num22);
						}
						break;
					}
					case 3:
					{
						Point point5 = Utils.SelectRandom<Point>(GenBase._random, choices);
						WorldGen.PlaceTile(num21, num22, point5.X, true, false, -1, point5.Y);
						break;
					}
					}
				}
			}
			foreach (Rectangle room2 in list)
			{
				item.ProcessRoom(room2);
			}
			bool flag6 = false;
			foreach (Rectangle rectangle14 in list)
			{
				int num24 = rectangle14.Height - 1 + rectangle14.Y;
				int style2 = (num24 > (int)Main.worldSurface) ? item.ChestStyle : 0;
				for (int num25 = 0; num25 < 10; num25++)
				{
					int i2 = GenBase._random.Next(2, rectangle14.Width - 2) + rectangle14.X;
					if (flag6 = WorldGen.AddBuriedChest(i2, num24, 0, false, style2))
					{
						break;
					}
				}
				if (flag6)
				{
					break;
				}
				int num26 = rectangle14.X + 2;
				while (num26 <= rectangle14.X + rectangle14.Width - 2 && !(flag6 = WorldGen.AddBuriedChest(num26, num24, 0, false, style2)))
				{
					num26++;
				}
				if (flag6)
				{
					break;
				}
			}
			if (!flag6)
			{
				foreach (Rectangle rectangle15 in list)
				{
					int num27 = rectangle15.Y - 1;
					int style3 = (num27 > (int)Main.worldSurface) ? item.ChestStyle : 0;
					for (int num28 = 0; num28 < 10; num28++)
					{
						int i3 = GenBase._random.Next(2, rectangle15.Width - 2) + rectangle15.X;
						if (flag6 = WorldGen.AddBuriedChest(i3, num27, 0, false, style3))
						{
							break;
						}
					}
					if (flag6)
					{
						break;
					}
					int num29 = rectangle15.X + 2;
					while (num29 <= rectangle15.X + rectangle15.Width - 2 && !(flag6 = WorldGen.AddBuriedChest(num29, num27, 0, false, style3)))
					{
						num29++;
					}
					if (flag6)
					{
						break;
					}
				}
			}
			if (!flag6)
			{
				for (int num30 = 0; num30 < 1000; num30++)
				{
					int i4 = GenBase._random.Next(list[0].X - 30, list[0].X + 30);
					int num31 = GenBase._random.Next(list[0].Y - 30, list[0].Y + 30);
					int style4 = (num31 > (int)Main.worldSurface) ? item.ChestStyle : 0;
					if (flag6 = WorldGen.AddBuriedChest(i4, num31, 0, false, style4))
					{
						break;
					}
				}
			}
			if (item == CaveHouseBiome.BuildData.Jungle && this._sharpenerCount < GenBase._random.Next(2, 5))
			{
				bool flag7 = false;
				foreach (Rectangle rectangle16 in list)
				{
					int num32 = rectangle16.Height - 2 + rectangle16.Y;
					for (int num33 = 0; num33 < 10; num33++)
					{
						int num34 = GenBase._random.Next(2, rectangle16.Width - 2) + rectangle16.X;
						WorldGen.PlaceTile(num34, num32, 377, true, true, -1, 0);
						if (flag7 = (GenBase._tiles[num34, num32].active() && GenBase._tiles[num34, num32].type == 377))
						{
							break;
						}
					}
					if (flag7)
					{
						break;
					}
					int num35 = rectangle16.X + 2;
					while (num35 <= rectangle16.X + rectangle16.Width - 2 && !(flag7 = WorldGen.PlaceTile(num35, num32, 377, true, true, -1, 0)))
					{
						num35++;
					}
					if (flag7)
					{
						break;
					}
				}
				if (flag7)
				{
					this._sharpenerCount++;
				}
			}
			if (item == CaveHouseBiome.BuildData.Desert && this._extractinatorCount < GenBase._random.Next(2, 5))
			{
				bool flag8 = false;
				foreach (Rectangle rectangle17 in list)
				{
					int num36 = rectangle17.Height - 2 + rectangle17.Y;
					for (int num37 = 0; num37 < 10; num37++)
					{
						int num38 = GenBase._random.Next(2, rectangle17.Width - 2) + rectangle17.X;
						WorldGen.PlaceTile(num38, num36, 219, true, true, -1, 0);
						if (flag8 = (GenBase._tiles[num38, num36].active() && GenBase._tiles[num38, num36].type == 219))
						{
							break;
						}
					}
					if (flag8)
					{
						break;
					}
					int num39 = rectangle17.X + 2;
					while (num39 <= rectangle17.X + rectangle17.Width - 2 && !(flag8 = WorldGen.PlaceTile(num39, num36, 219, true, true, -1, 0)))
					{
						num39++;
					}
					if (flag8)
					{
						break;
					}
				}
				if (flag8)
				{
					this._extractinatorCount++;
				}
			}
			return true;
		}

		// Token: 0x060025D0 RID: 9680 RVA: 0x0001A778 File Offset: 0x00018978
		public override void Reset()
		{
			this._sharpenerCount = 0;
			this._extractinatorCount = 0;
		}

		// Token: 0x060025D1 RID: 9681 RVA: 0x0048BFD0 File Offset: 0x0048A1D0
		internal static void AgeDefaultRoom(Rectangle room)
		{
			for (int i = 0; i < room.Width * room.Height / 16; i++)
			{
				int x = GenBase._random.Next(1, room.Width - 1) + room.X;
				int y = GenBase._random.Next(1, room.Height - 1) + room.Y;
				WorldUtils.Gen(new Point(x, y), new Shapes.Rectangle(2, 2), Actions.Chain(new GenAction[]
				{
					new Modifiers.Dither(0.5),
					new Modifiers.Blotches(2, 2.0),
					new Modifiers.IsEmpty(),
					new Actions.SetTile(51, true, true)
				}));
			}
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.85000002384185791),
				new Modifiers.Blotches(2, 0.3),
				new Modifiers.OnlyWalls(new byte[]
				{
					CaveHouseBiome.BuildData.Default.Wall
				}),
				((double)room.Y > Main.worldSurface) ? new Actions.ClearWall(true) : new Actions.PlaceWall(2, true)
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.949999988079071),
				new Modifiers.OnlyTiles(new ushort[]
				{
					30,
					321,
					158
				}),
				new Actions.ClearTile(true)
			}));
		}

		// Token: 0x060025D2 RID: 9682 RVA: 0x0048C184 File Offset: 0x0048A384
		internal static void AgeSnowRoom(Rectangle room)
		{
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.60000002384185791),
				new Modifiers.Blotches(2, 0.60000002384185791),
				new Modifiers.OnlyTiles(new ushort[]
				{
					CaveHouseBiome.BuildData.Snow.Tile
				}),
				new Actions.SetTile(161, true, true),
				new Modifiers.Dither(0.8),
				new Actions.SetTile(147, true, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					161
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y + room.Height - 1), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					161
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.85000002384185791),
				new Modifiers.Blotches(2, 0.8),
				((double)room.Y > Main.worldSurface) ? new Actions.ClearWall(true) : new Actions.PlaceWall(40, true)
			}));
		}

		// Token: 0x060025D3 RID: 9683 RVA: 0x0048C388 File Offset: 0x0048A588
		internal static void AgeDesertRoom(Rectangle room)
		{
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.800000011920929),
				new Modifiers.Blotches(2, 0.20000000298023224),
				new Modifiers.OnlyTiles(new ushort[]
				{
					CaveHouseBiome.BuildData.Desert.Tile
				}),
				new Actions.SetTile(396, true, true),
				new Modifiers.Dither(0.5),
				new Actions.SetTile(397, true, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					397,
					396
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y + room.Height - 1), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					397,
					396
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.800000011920929),
				new Modifiers.Blotches(2, 0.3),
				new Modifiers.OnlyWalls(new byte[]
				{
					CaveHouseBiome.BuildData.Desert.Wall
				}),
				new Actions.PlaceWall(216, true)
			}));
		}

		// Token: 0x060025D4 RID: 9684 RVA: 0x0048C5A4 File Offset: 0x0048A7A4
		internal static void AgeGraniteRoom(Rectangle room)
		{
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.60000002384185791),
				new Modifiers.Blotches(2, 0.60000002384185791),
				new Modifiers.OnlyTiles(new ushort[]
				{
					CaveHouseBiome.BuildData.Granite.Tile
				}),
				new Actions.SetTile(368, true, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.800000011920929),
				new Modifiers.OnlyTiles(new ushort[]
				{
					368
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y + room.Height - 1), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.800000011920929),
				new Modifiers.OnlyTiles(new ushort[]
				{
					368
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.85000002384185791),
				new Modifiers.Blotches(2, 0.3),
				new Actions.PlaceWall(180, true)
			}));
		}

		// Token: 0x060025D5 RID: 9685 RVA: 0x0048C774 File Offset: 0x0048A974
		internal static void AgeMarbleRoom(Rectangle room)
		{
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.60000002384185791),
				new Modifiers.Blotches(2, 0.60000002384185791),
				new Modifiers.OnlyTiles(new ushort[]
				{
					CaveHouseBiome.BuildData.Marble.Tile
				}),
				new Actions.SetTile(367, true, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.800000011920929),
				new Modifiers.OnlyTiles(new ushort[]
				{
					367
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y + room.Height - 1), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.800000011920929),
				new Modifiers.OnlyTiles(new ushort[]
				{
					367
				}),
				new Modifiers.Offset(0, 1),
				new ActionStalagtite()
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.85000002384185791),
				new Modifiers.Blotches(2, 0.3),
				new Actions.PlaceWall(178, true)
			}));
		}

		// Token: 0x060025D6 RID: 9686 RVA: 0x0048C944 File Offset: 0x0048AB44
		internal static void AgeMushroomRoom(Rectangle room)
		{
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.699999988079071),
				new Modifiers.Blotches(2, 0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					CaveHouseBiome.BuildData.Mushroom.Tile
				}),
				new Actions.SetTile(70, true, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.60000002384185791),
				new Modifiers.OnlyTiles(new ushort[]
				{
					70
				}),
				new Modifiers.Offset(0, -1),
				new Actions.SetTile(71, false, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y + room.Height - 1), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.60000002384185791),
				new Modifiers.OnlyTiles(new ushort[]
				{
					70
				}),
				new Modifiers.Offset(0, -1),
				new Actions.SetTile(71, false, true)
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.85000002384185791),
				new Modifiers.Blotches(2, 0.3),
				new Actions.ClearWall(false)
			}));
		}

		// Token: 0x060025D7 RID: 9687 RVA: 0x0048CB10 File Offset: 0x0048AD10
		internal static void AgeJungleRoom(Rectangle room)
		{
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.60000002384185791),
				new Modifiers.Blotches(2, 0.60000002384185791),
				new Modifiers.OnlyTiles(new ushort[]
				{
					CaveHouseBiome.BuildData.Jungle.Tile
				}),
				new Actions.SetTile(60, true, true),
				new Modifiers.Dither(0.800000011920929),
				new Actions.SetTile(59, true, true)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					60
				}),
				new Modifiers.Offset(0, 1),
				new ActionVines(3, room.Height, 62)
			}));
			WorldUtils.Gen(new Point(room.X + 1, room.Y + room.Height - 1), new Shapes.Rectangle(room.Width - 2, 1), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.5),
				new Modifiers.OnlyTiles(new ushort[]
				{
					60
				}),
				new Modifiers.Offset(0, 1),
				new ActionVines(3, room.Height, 62)
			}));
			WorldUtils.Gen(new Point(room.X, room.Y), new Shapes.Rectangle(room.Width, room.Height), Actions.Chain(new GenAction[]
			{
				new Modifiers.Dither(0.85000002384185791),
				new Modifiers.Blotches(2, 0.3),
				new Actions.PlaceWall(64, true)
			}));
		}

		// Token: 0x0400416B RID: 16747
		private const int VERTICAL_EXIT_WIDTH = 3;

		// Token: 0x0400416C RID: 16748
		public static bool[] _blacklistedTiles = TileID.Sets.Factory.CreateBoolSet(true, new int[]
		{
			225,
			41,
			43,
			44,
			226,
			203,
			112,
			25,
			151
		});

		// Token: 0x0400416D RID: 16749
		private int _sharpenerCount;

		// Token: 0x0400416E RID: 16750
		private int _extractinatorCount;

		// Token: 0x0200044D RID: 1101
		private class BuildData
		{
			// Token: 0x060025DA RID: 9690 RVA: 0x0048CD04 File Offset: 0x0048AF04
			public static CaveHouseBiome.BuildData CreateSnowData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 321,
					Wall = 149,
					DoorStyle = 30,
					PlatformStyle = 19,
					TableStyle = 28,
					WorkbenchStyle = 23,
					PianoStyle = 23,
					BookcaseStyle = 25,
					ChairStyle = 30,
					ChestStyle = 11,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeSnowRoom)
				};
			}

			// Token: 0x060025DB RID: 9691 RVA: 0x0048CD80 File Offset: 0x0048AF80
			public static CaveHouseBiome.BuildData CreateDesertData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 396,
					Wall = 187,
					PlatformStyle = 0,
					DoorStyle = 0,
					TableStyle = 0,
					WorkbenchStyle = 0,
					PianoStyle = 0,
					BookcaseStyle = 0,
					ChairStyle = 0,
					ChestStyle = 1,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeDesertRoom)
				};
			}

			// Token: 0x060025DC RID: 9692 RVA: 0x0048CDF4 File Offset: 0x0048AFF4
			public static CaveHouseBiome.BuildData CreateJungleData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 158,
					Wall = 42,
					PlatformStyle = 2,
					DoorStyle = 2,
					TableStyle = 2,
					WorkbenchStyle = 2,
					PianoStyle = 2,
					BookcaseStyle = 12,
					ChairStyle = 3,
					ChestStyle = 8,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeJungleRoom)
				};
			}

			// Token: 0x060025DD RID: 9693 RVA: 0x0048CE68 File Offset: 0x0048B068
			public static CaveHouseBiome.BuildData CreateGraniteData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 369,
					Wall = 181,
					PlatformStyle = 28,
					DoorStyle = 34,
					TableStyle = 33,
					WorkbenchStyle = 29,
					PianoStyle = 28,
					BookcaseStyle = 30,
					ChairStyle = 34,
					ChestStyle = 50,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeGraniteRoom)
				};
			}

			// Token: 0x060025DE RID: 9694 RVA: 0x0048CEE4 File Offset: 0x0048B0E4
			public static CaveHouseBiome.BuildData CreateMarbleData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 357,
					Wall = 179,
					PlatformStyle = 29,
					DoorStyle = 35,
					TableStyle = 34,
					WorkbenchStyle = 30,
					PianoStyle = 29,
					BookcaseStyle = 31,
					ChairStyle = 35,
					ChestStyle = 51,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeMarbleRoom)
				};
			}

			// Token: 0x060025DF RID: 9695 RVA: 0x0048CF60 File Offset: 0x0048B160
			public static CaveHouseBiome.BuildData CreateMushroomData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 190,
					Wall = 74,
					PlatformStyle = 18,
					DoorStyle = 6,
					TableStyle = 27,
					WorkbenchStyle = 7,
					PianoStyle = 22,
					BookcaseStyle = 24,
					ChairStyle = 9,
					ChestStyle = 32,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeMushroomRoom)
				};
			}

			// Token: 0x060025E0 RID: 9696 RVA: 0x0048CFD8 File Offset: 0x0048B1D8
			public static CaveHouseBiome.BuildData CreateDefaultData()
			{
				return new CaveHouseBiome.BuildData
				{
					Tile = 30,
					Wall = 27,
					PlatformStyle = 0,
					DoorStyle = 0,
					TableStyle = 0,
					WorkbenchStyle = 0,
					PianoStyle = 0,
					BookcaseStyle = 0,
					ChairStyle = 0,
					ChestStyle = 1,
					ProcessRoom = new CaveHouseBiome.BuildData.ProcessRoomMethod(CaveHouseBiome.AgeDefaultRoom)
				};
			}

			// Token: 0x0400416F RID: 16751
			public static CaveHouseBiome.BuildData Snow = CaveHouseBiome.BuildData.CreateSnowData();

			// Token: 0x04004170 RID: 16752
			public static CaveHouseBiome.BuildData Jungle = CaveHouseBiome.BuildData.CreateJungleData();

			// Token: 0x04004171 RID: 16753
			public static CaveHouseBiome.BuildData Default = CaveHouseBiome.BuildData.CreateDefaultData();

			// Token: 0x04004172 RID: 16754
			public static CaveHouseBiome.BuildData Granite = CaveHouseBiome.BuildData.CreateGraniteData();

			// Token: 0x04004173 RID: 16755
			public static CaveHouseBiome.BuildData Marble = CaveHouseBiome.BuildData.CreateMarbleData();

			// Token: 0x04004174 RID: 16756
			public static CaveHouseBiome.BuildData Mushroom = CaveHouseBiome.BuildData.CreateMushroomData();

			// Token: 0x04004175 RID: 16757
			public static CaveHouseBiome.BuildData Desert = CaveHouseBiome.BuildData.CreateDesertData();

			// Token: 0x04004176 RID: 16758
			public ushort Tile;

			// Token: 0x04004177 RID: 16759
			public byte Wall;

			// Token: 0x04004178 RID: 16760
			public int PlatformStyle;

			// Token: 0x04004179 RID: 16761
			public int DoorStyle;

			// Token: 0x0400417A RID: 16762
			public int TableStyle;

			// Token: 0x0400417B RID: 16763
			public int WorkbenchStyle;

			// Token: 0x0400417C RID: 16764
			public int PianoStyle;

			// Token: 0x0400417D RID: 16765
			public int BookcaseStyle;

			// Token: 0x0400417E RID: 16766
			public int ChairStyle;

			// Token: 0x0400417F RID: 16767
			public int ChestStyle;

			// Token: 0x04004180 RID: 16768
			public CaveHouseBiome.BuildData.ProcessRoomMethod ProcessRoom;

			// Token: 0x0200044E RID: 1102
			// (Invoke) Token: 0x060025E4 RID: 9700
			public delegate void ProcessRoomMethod(Rectangle room);
		}
	}
}
